// utils/friendUtils.js
const User = require('../models/User');

async function getFriendList(userId) {
  try {
    const user = await User.findOne({ userId });
    if (!user || !user.friends) return [];

    const friends = await User.find({ userId: { $in: user.friends.map(f => f.userId) } });

    return friends.map(friend => ({
      userId: friend.userId,
      nickname: friend.nickname,
      avatar: friend.avatar
    }));
  } catch (err) {
    console.error('获取好友列表失败:', err);
    return [];
  }
}

module.exports = { getFriendList };
